//
// Copyright (C) Robert Bosch GmbH
// Date: March 2010
// Author: CR/RTC2-AP Kui Xu
#ifndef _IM_NLU_OSAL
#define _IM_NLU_OSAL

#include <string>
#include <vector>
#include <fstream>
#include <list>
#include <map>

class UIMemory
{
public:
	UIMemory(void) {};
	virtual	~UIMemory(void) {};

	static void* ReserveMemory(size_t stAllocSize);
	static void ReleaseMemory(void *pMemory);
	static void ReleaseMemoryArray(void *pMemory);
};

class UILogFile {
public:
	void openFile(const char* filename);
	void closeFile();
	void writeLine(const char *dest);
	void setEnable(bool e);
private:
	bool enable;
	std::ofstream ofs;
};

class UIFile
{
public:
	UIFile(void) {};
	virtual ~UIFile(void) {};

	void openFile(const char* filename);
	void openOutFile(const char* filename);
	void openFileBin(const char* filename);
	void closeFile();
	void closeOutFile();
	int fileLen();
	void movePointerTo(int i);
	bool isOpen();
	bool getLine(std::string &line);
	void readBuff(char * dest, int n);
	void getChar(char &dest);
	void writeLine(const char *dest);
	bool isEOF();
	static void mkdir(const char* dirname);

private:
	std::ifstream ifs;
	std::ofstream ofs;
};


#if !defined(_WIN32) && !defined(_WIN64) // Linux - Unix
	#  include <sys/time.h>
	typedef timeval sys_time_t;
	inline void system_time(sys_time_t* t) {
		gettimeofday(t, NULL);
	}
	inline long long time_to_msec(const sys_time_t& t) {
		return t.tv_sec * 1000LL + t.tv_usec / 1000;
	}
	#else // Windows and MinGW
	#  include <sys/timeb.h>
	typedef _timeb sys_time_t;
	inline void system_time(sys_time_t* t) { _ftime(t); }
	inline long long time_to_msec(const sys_time_t& t) {
		return t.time * 1000LL + t.millitm;
	}
#endif

#endif
